package com.myBlog.controller;

import com.myBlog.domain.ResponseResult;
import com.myBlog.domain.dto.TagListDTO;
import com.myBlog.domain.vo.PageVo;
import com.myBlog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Resource
    private TagService tagService;

    /**
     * 分页查询标签
     *
     * @param pageNum
     * @param pageSize
     * @param tagListDTO
     * @return
     */
    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDTO tagListDTO) {
        return tagService.list(pageNum, pageSize, tagListDTO);
    }

    @GetMapping("{id}")
    public ResponseResult getTagInfo(@PathVariable("id") Long tagId) {
        return tagService.getTagInfo(tagId);
    }

    /**
     * 新增标签
     *
     * @param tagListDTO
     * @return
     */
    @PostMapping
    public ResponseResult addTag(@RequestBody TagListDTO tagListDTO) {
        return tagService.addTag(tagListDTO);
    }

    /**
     * 根据id删除标签
     *
     * @param ids
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") List<Long> ids) {
        return tagService.deleteById(ids);
    }

    /**
     * 修改标签
     *
     * @param tagListDTO
     * @return
     */
    @PutMapping
    public ResponseResult updateTag(@RequestBody TagListDTO tagListDTO) {
        return tagService.updateTag(tagListDTO);
    }

    /**
     * 查询全部标签
     *
     * @return
     */
    @GetMapping("/listAllTag")
    public ResponseResult listAllTag() {
        return ResponseResult.okResult(tagService.listAllTag());
    }

}
